home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12697 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  121 lines

  1. Path: news.primenet.com!bjg
  2. From: Brad Grossman <bjg@primenet.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Help needed with class for filename data
  5. Date: 21 Mar 1996 00:21:01 -0700
  6. Organization: Primenet (602)395-1010
  7. Sender: root@primenet.com
  8. Message-ID: <4ir00t$33m@nnrp1.news.primenet.com>
  9. X-Posted-By: bjg@usr1.primenet.com
  10.  
  11. ....I'm trying to make a class that will take a sorted directory of a 
  12. directory, and then use the info for a few things.  When I try to use the 
  13. class I'm using for storing the file info in a direct sorted array of 
  14. either my design or that in Borland C++ 3.0 container classes or indirect 
  15. ones of my design (it does work with indirect container classes, but 
  16. since they can't be expanded, they are of little use) the machine 
  17. crashes.  I have given up on figuring out the problem on my own, and need 
  18. help...I cannot see what is going wrong.  Here is the heart of the class:
  19.  
  20. class FileData: public Date, public Time
  21. {
  22. protected:
  23.  
  24.     char *fileName;
  25.     char *ext;
  26.     Date fileDate;
  27.     Time fileTime;
  28.     long fileSize;
  29.  
  30. };
  31.  
  32. FileData::FileData() :
  33.     fileDate(1,1,80),
  34.     fileTime()
  35.  
  36. {
  37.     fileName="";
  38.     ext="";
  39.     fileSize=0;
  40. };
  41.  
  42. FileData::~FileData()
  43. {
  44.     delete fileName;
  45.     delete ext;
  46. }
  47.  
  48. FileData::FileData( ffblk& blk ) :
  49.     fileDate( (blk.ff_fdate >> 5) & 0x000F,
  50.           blk.ff_fdate & 0x0001F,
  51.           (blk.ff_fdate >> 9) + 80 ),
  52.     fileSize( blk.ff_fsize ),
  53.     fileTime( blk.ff_ftime >> 11,
  54.           (blk.ff_ftime >> 5) & 0x3F,
  55.           blk.ff_ftime & 0x1F )
  56. {
  57.     int ex = 0;
  58.     fileName = new char[8];
  59.     ext = new char[3];
  60.  
  61.  
  62.      for (int i=0; i < 12; i++) {
  63.  
  64.     if (blk.ff_name[i] == '.') {
  65.     fileName[i] = '\0';
  66.     ex = i+1;
  67.         continue;
  68.         };
  69.  
  70.     if ((blk.ff_name[i] == ' ' || blk.ff_name[i] == '\0') && ex ) {
  71.     ext[i-ex]='\0';
  72.         break;
  73.     };
  74.  
  75.  
  76.     if (!ex ) {
  77.     fileName[i] = blk.ff_name[i];
  78.     };
  79.  
  80.     if (ex) {
  81.     ext[i-ex] = blk.ff_name[i];
  82.     };
  83.  
  84. };
  85. fileName[8]='\0';
  86. ext[3]='\0';
  87.  
  88. };
  89.  
  90. FileData& FileData::operator=(const FileData &f)
  91. {
  92.     delete fileName;
  93.     delete ext;
  94.     fileName = new char[8];
  95.     ext = new char[3];
  96.     strcpy(fileName,f.fileName);
  97.     strcpy(ext,f.ext);
  98.     fileSize=f.fileSize;
  99.     fileDate=f.fileDate;
  100.     fileTime=f.fileTime;
  101.     if (this==&f) return *this;
  102. };
  103.  
  104. FileData::FileData(const FileData &f)
  105. {
  106.     strcpy(fileName,f.fileName);
  107.     strcpy(ext,f.ext);
  108.     fileSize=f.fileSize;
  109.     fileDate=f.fileDate;
  110.     fileTime=f.fileTime;
  111. };
  112.  
  113. The problem is somewhere in here...some problem in memory allocation 
  114. probably.  Please mail me if you can figure out what is going wrong 
  115. here...or if you have a working framework for this sort of thing...
  116.  
  117.  
  118. --
  119. Brad Grossman        "Energy derives from both the plus and negative"    
  120.                                    Metallica, Eye of the Beholder
  121.